<?php
  require_once('../config.inc.php');

   require_once($config['app_dir'] . '/includes/db.class.php');
   require_once($config['app_dir'] . '/includes/template.class.php');
   require_once($config['app_dir'] . '/classes/log.class.php');
   require_once($config['app_dir'] . '/classes/translation.class.php');



class objNews {	var $lastRate; // latest rate time
	var $checkPeriod = 180; // rates shouldn't be older than ... seconds

	function __construct() {
       $db = $this->db = objDataBase::GetInstance();//new objDataBase();

 	} //constructor

 	function setTranslationMessage($lang) {
       $TranslationMessage = objTranslationMessage::GetInstance();
    	$TranslationMessage->SetLang($lang);
    	$this->TranslationMessage = $TranslationMessage;
 	}


	public function getHeadersArr() {
		$newsArr = array();

  		$query="select ID, NameID, DisplayDate, isNew from fa_news where Active=1 and FrontPage=1 order by DisplayDate desc";
    	try {
          	$rs = $this->db->Execute($query);
	     	if ($rs) {
				while (!$rs->EOF) {
                 $newsArr[] = array(
	                	'id' => $rs->fields['ID'],
	                	'displayDate' => date("m-d-y",$rs->fields['DisplayDate']),
	                	'header' => $this->TranslationMessage->GetMessage('news_headers__'.$rs->fields['NameID']),
	                	'content' => $this->TranslationMessage->GetMessage('news_content__'.$rs->fields['NameID']),
	                	'name' => $rs->fields['NameID'],
	                	'new' => $rs->fields['isNew']
	                );
				  	$rs->MoveNext();
				}
			}

          $this->lastRate = $rs->fields['lastRate'];
       }
       catch (exception $e) {
           if (true == $this->db->debug ) {
             adodb_pr($e);
             $e = adodb_backtrace($e->trace);
           }
           die('DB Error: '.$e->sql);
       }
        return $newsArr;
	}

		public function getCenterHeadersArr() {
		$newsArr = array();

  		$query="select ID, NameID, DisplayDate from fa_news where Active=1 and FrontPageCenter=1 order by DisplayDate desc";
    	try {
          	$rs = $this->db->Execute($query);
	     	if ($rs) {
				while (!$rs->EOF) {
                 $newsArr[] = array(
	                	'id' => $rs->fields['ID'],
	                	'displayDate' => date("d.m.y",$rs->fields['DisplayDate']),
	                	'header' => $this->TranslationMessage->GetMessage('news_headers__'.$rs->fields['NameID']),
	                	'name' => $rs->fields['NameID']
	                );
				  	$rs->MoveNext();
				}
			}

          $this->lastRate = $rs->fields['lastRate'];
       }
       catch (exception $e) {
           if (true == $this->db->debug ) {
             adodb_pr($e);
             $e = adodb_backtrace($e->trace);
           }
           die('DB Error: '.$e->sql);
       }
        return $newsArr;
	}


	public function getNewsArr() {		$newsArr = array();

  		$query="select * from fa_news where Active=1 order by DisplayDate desc";
    	try {
          	$rs = $this->db->Execute($query);
	     	if ($rs) {
				while (!$rs->EOF) {
                 $newsArr[] = array(
	                	'id' => $rs->fields['ID'],
	                	'displayDate' => date("d-m-Y",$rs->fields['DisplayDate']),
	                	'header' => $this->TranslationMessage->GetMessage('news_headers__'.$rs->fields['NameID']),
	                	'content' => $this->TranslationMessage->GetMessage('news_content__'.$rs->fields['NameID']),
	                	'name' => $rs->fields['NameID'],
	                	'new' => $rs->fields['isNew']
	                );
				  	$rs->MoveNext();
				}
			}



          $this->lastRate = $rs->fields['lastRate'];
       }
       catch (exception $e) {
           if (true == $this->db->debug ) {
             adodb_pr($e);
             $e = adodb_backtrace($e->trace);
           }
           die('DB Error: '.$e->sql);
       }
        return $newsArr;
	}

}


?>